<template>
  <div class="container">
    <h3>用户登录</h3>
    <div class="form">
        <ul>
          <li>
            用户名:<input type="text" v-model="username">
          </li>
          <li>
            密码:<input type="password" v-model="password">
          </li>
        </ul>
        <button @click="login">登录</button>
      </div>
  </div>
</template>
<script setup>
import { ref,onMounted } from 'vue'
import { useRouter,useRoute} from 'vue-router'
const username = ref('')
const password = ref('')
const router = useRouter()
const route = useRoute()
const login = () => {
  const userInfo = JSON.parse(window.localStorage.getItem('userInfo'))
  if (userInfo) {
    if (userInfo.username == username.value && userInfo.password == password.value) {
      window.localStorage.setItem('token', username.value + password.value)
      router.push('/')
    } else { 
      alert('用户名或者密码不正确')
    }
  } else { 
    alert('用户尚未注册')
  }
  
}
onMounted(() => { 
  username.value = route.query.username
  password.value = route.query.password
})
</script>
<style>
.container{
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
li{
  list-style: none;
}
</style>
  